package com.hongxun.design.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hongxun.design.R;
import com.hongxun.design.bean.LogProjectBean;

import java.util.List;

/**
 * Created by zerdoor_pc on 2016/7/1.
 */
public class LogEditAdapter extends BaseAdapter {
    Context context;
    List<LogProjectBean> listBeans;
    LayoutInflater inflater;
    boolean isedit = false;
    public LogEditAdapter(Context context, List<LogProjectBean> listBeans) {
        this.context = context;
        this.listBeans = listBeans;
        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return listBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return listBeans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        LogProjectBean bean = (LogProjectBean) getItem(i);
        ItemHolldler itemHolldler = null;
        if (view == null) {
            view = inflater.inflate(R.layout.listview_item_logedit, null);
            itemHolldler = new ItemHolldler(view);
            view.setTag(itemHolldler);
        } else {
            itemHolldler = (ItemHolldler) view.getTag();
        }
        try {
            itemHolldler.item.setVisibility(View.VISIBLE);
            itemHolldler.name.setText(SetText(bean.getStage_name()));
            itemHolldler.value.setText(SetText(bean.getProject_statis()));

        } catch (Exception e) {
        }
        return view;
    }


    private String SetText(String s) {
        if (s == null || s.length() == 0) {
            return "暂无数据";
        }
        return s;
    }


    class ItemHolldler {
        TextView name;
        EditText value;
        LinearLayout item;

        ItemHolldler(View v) {
            item = (LinearLayout) v.findViewById(R.id.log_item);
            name = (TextView) v.findViewById(R.id.log_name);
            value = (EditText) v.findViewById(R.id.log_value);
            value.setEnabled(false);
        }
    }


}
